﻿package org.display.util
{
	
	import flash.filesystem.File;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import mx.controls.*;
	
	import org.data.Global;
	import org.display.graphic.*;
	import org.enmu.AbcType;
	import org.utils.*;

	public class CreateClass
	{
		public function CreateClass(scene,scaneName:String,classType,lockPath)
		{
			//自动转换类名第一个字母为大写
			scaneName=StringControl.onewordUp(scaneName)
			//scaneName=scaneName.replace(new RegExp(scaneName.charAt(0)),scaneName.charAt(0).toUpperCase())

			Global.classType_jsfl=classType
			
			var arr:Array=lockPath.split("\\")
			arr.shift()
			
			var objs:Array=ElementControl.getObjs(ShapeBase,scene)
			
			//过滤名字==================================================
			for(var i=0; i<objs.length;i++){
				var obj:ShapeBase=objs[i]
				if(obj.getName()==""){
					obj.showTxtField()
					Alert.show("对象名字不能为空！")
					return;
				}
			}
						
			doview(arr.concat(),objs,scaneName)

			//domodel(arr.concat(),objs)
			
			//docommand(arr.concat(),objs,scaneName)
			
			//docommandControl(arr.concat(),objs,scaneName,scene)
			
			dojsfl(arr.concat(),objs,scaneName,scene)
			
			doevents(objs,scaneName)
			
			//doModelProxy(arr,objs,scaneName)
			doViewProxy(arr,objs,scaneName)
			
			dosave(scaneName)
			
			doxml(objs,scaneName,scene)

			Global.reinit()
				
			new CreateCommandControl()
			
		}
		
		
		function doxml(objs,scaneName,scene){
		
			var viewClass:String=Global.package_view+"."+scaneName+"View"
			//var modelClass:String=Global.package_model+"."+scaneName+"Model"
				
			var source:XML=<data>
				          <name>{scaneName}</name>
                        <type>{AbcType.CLASSTYPE}</type>
                        <view>{viewClass}</view>
                        </data>
			
			var points:Array=[]
			for(var  i=0; i<objs.length;i++){
				var obj:ShapeBase=objs[i] as ShapeBase	
					
				var rec:Rectangle=obj.getBounds(scene)
					
				points.push(new Point(rec.x,rec.y))	
			    }
			
			points=ArrayControl.orderX(points)
			//var maxX:Number=points[0].x
			var minX:Number=points[0].x
				
			points=ArrayControl.orderY(points)
			//var maxY:Number=points[0].y
			var minY:Number=points[0].y
				
           
			for(var  i=0; i<objs.length;i++){
				var obj:ShapeBase=objs[i] as ShapeBase	
				rec=obj.getBounds(scene)
				var isevt:Boolean=obj.getEvent()!=""?true:false
				
				var item:XML=<item></item>
				item.appendChild(<name>{obj.getName()}</name>)
				item.appendChild(<x>{rec.x-minX}</x>)
				item.appendChild(<y>{rec.y-minY}</y>)
				item.appendChild(<w>{rec.width-2}</w>)
				item.appendChild(<h>{rec.height-2}</h>)
				item.appendChild(<event>{isevt}</event>)
					
				if(obj.getName().split("_")[obj.getName().split("_").length-1]=="iv"){
				
					item.appendChild(<path>{Iv(obj).path.replace(/.*?(?=\/xml\/)/gis,"")}</path>)
						
				}
					
				source.appendChild(item)
			}
			
			switch(Global.classType_jsfl){
				
				
				case AbcType.DOCUMENTCLASSTYPE:
					
					//var xmlpath:String=Global.workspace.replace(/\\/gis,"/")+"/xml/module/"+Global.package_view.replace(/\./gis,"/")+"/"+scaneName+"View.xml"
					
					break
				
				case AbcType.CLASSTYPE:
					
				case AbcType.MOUDLECLASSTYPE:
					
					var arr:Array=Global.package_view.split(".")
					arr.pop()
					var xmlpath=Global.workspace.replace(/\\/gis,"/")+"/xml/"+arr.join("/")+"/"+scaneName+"View.xml"
					
					//补丁如果是没有锁定发布文件夹==================================
					if(scene is Iv){ xmlpath=Iv(scene).path }
					
					break
				
			}
	
			FileControl.saveFile(xmlpath,source.toXMLString())
				
			Global.xmlPath=xmlpath

		}
		
		function dojsfl(arr,objs,scaneName,scene){
		
			//jsfl替换内容======================================

			Global.symbolLinkage_jsfl=arr.join(".")+".view."+scaneName+"View"
			
			Global.items_jsfl+="["
				
			for(var  i=0; i<objs.length;i++){
				var obj=objs[i]
				var rec:Rectangle=obj.getBounds(scene)
					
				var oop:String="{name:\""+obj.getName()+"\",x:"+rec.x+",y:"+rec.y+",w:"+rec.width+",h:"+rec.height+",path:\"null\"}"
				
				if(obj is Iv){
					
					//file:///D:/abcFF/xml/org/display/aishi/TestView.xml
					
					var items:Array=Iv(obj).path.replace(/file:\/\/\//gis,"").split("\/")
					items.pop()

					var objPath:String=items.join("/")
					
					var viewPath:String=Global.workspace.replace(/\\/gis,"/")+"/xml/"+Global.package_view.replace(/\./gis,"/")
					var item:Array=viewPath.split("\/")
					item.pop()
					viewPath=item.join("\/")
	
					var path:String=Iv(obj).path.replace(/\.xml/gis,".jpg").replace(/\/xml\//gis,"/swf/")
						
					if(path.indexOf("file:///")==-1)path="file:///"+path
					
					if(objPath!=viewPath){

					   //oop="{name:\""+obj.getName()+"\",x:"+rec.x+",y:"+rec.y+",w:"+rec.width+",h:"+rec.height+",path:\""+path+"\"}"
				
					}
					
				}
					
				if(i==objs.length-1)
				{Global.items_jsfl+=oop}
				else
				{Global.items_jsfl+=oop+","}
			}
			
			Global.items_jsfl+="]"
				
			Global.as3PackagePath_jsfl=Global.workspace.replace(/\\/gis,"/")+";"+Global.workspace.replace(/\\/gis,"/")+"/openSource"
			
		}
		
		function doevents(objs,scaneName){

			objs=ArrayControl.orderDepth(objs)
			
			for(var i=0; i<objs.length;i++){
				
				var obj:ShapeBase=objs[i]
					
				var evtName:String=obj.getEvent().split(".")[obj.getEvent().split(".").length-1].replace(/Event/gis,"_Event")

					if(obj.getEvent()!=""){
						
						var evts:Array=obj.getEvent().split(".")
						
						evts.splice(evts.length-1,0,scaneName+"View")

						Global.var_event+="static public const "+evtName+":String = \""+evts.join(".")+"\"\n         "
						
					}
					
				}
			
			var regstr:String="public function AbcEventType(){"
				
			var newstr:String=Global.var_event+regstr
			
			Global.eventSource=Global.eventSource.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
		}
		
		function doModelProxy(arr,objs,scaneName){
			
			Global.package_modelProxy=arr.join(".")+".modelProxy"
			
			Global.import_modelProxy+="import "+arr.join(".")+".model.DefaultModel;\n       "
			Global.import_modelProxy+="import "+arr.join(".")+".view.DefaultView;\n       "
			
			for(var i=0; i<objs.length;i++){
				
				var obj:ShapeBase=objs[i]
				
				if(obj is Iv){
					
					Global.model_modelProxy+="\/\/view."+obj.getName()+".modelProxy.setData()\n       "
					
				}else{
					
					Global.view_modelProxy+="\/\/view."+obj.getName()+"\n          "
					
				}
				
			}

		}
		
		function doViewProxy(arr,objs,scaneName){
			
			Global.package_viewProxy=arr.join(".")+".viewProxy"
			
			//Global.import_viewProxy+="import "+arr.join(".")+".model.DefaultModel;\n       "
			Global.import_viewProxy+="import "+arr.join(".")+".view.DefaultView;\n       "

			for(var i=0; i<objs.length;i++){
				
				var obj:ShapeBase=objs[i]
					
				if(obj is Iv){
				
					Global.model_viewProxy+="\/\/view."+obj.getName()+".modelProxy.setData()\n       "
				
				}else{
				    
					Global.view_viewProxy+="\/\/view."+obj.getName()+"\n          "
				
				}
					
			}
			
			
	
		}
		
		function doview(arr,objs,scaneName){
			
			var asdoc:String=""
				
			var viewnames:Array=[]
		
			//view替换内容=========================================
			Global.package_view=arr.join(".")+".view"
				
			//Global.import_view+="import "+arr.join(".")+".modelProxy.DefaultModelProxy;\n     "
			Global.import_view+="import "+arr.join(".")+".viewProxy.DefaultViewProxy;\n     "
				
			objs=ArrayControl.orderDepth(objs)
			
			for(var i=0; i<objs.length;i++){
				
				var obj:ShapeBase=objs[i]
				
				viewnames.push(obj.getName())
					
				var arr:Array=obj.getName().split("_")
					
				switch(arr[arr.length-1]){
				
				
				case "mbt":
					Global.var_view+="public var "+obj.getName()+":MovieClip;\n		"
					
					break
					
				case "bt":
					
					Global.var_view+="public var "+obj.getName()+":SimpleButton;\n		"
					break
				
				case "tf":
					
					Global.var_view+="public var "+obj.getName()+":TextField;\n		"
					break
				
				case "mc":
					
					Global.var_view+="public var "+obj.getName()+":MovieClip;\n		"
					break
				
				case "iv":
					
					Global.var_view+="public var "+obj.getName()+":"+arr[0]+";\n		"
					break
				
				}	

				if(obj.getEvent()!=""){
					
					Global.onEnable_view+=obj.getName()+".addEventListener(MouseEvent.MOUSE_DOWN,mouseEvent);\n         "
					
					Global.offEnable_view+=obj.getName()+".removeEventListener(MouseEvent.MOUSE_DOWN,mouseEvent);\n         "
					
					var evtName:String=obj.getEvent().split(".")[obj.getEvent().split(".").length-1].replace(/Event/gis,"_Event")
					
					var evts:Array=obj.getEvent().split(".")
					evts.splice(evts.length-1,0,scaneName+"View")
						
					Global.mouseEvent_view+="case "+obj.getName()+":\n                ";
					if(obj.getEvent()!="")Global.mouseEvent_view+="AbcEventDispatcher.instance.dispatcher(\""+evts.join(".")+"\",this,e);\n               "
					Global.mouseEvent_view+="    break\n                        "
	
				}
				
				//判断模块是否为公共库=====================================================================
				
				if(obj is Iv){
					
				var items:Array=Iv(obj).path.replace(/file:\/\/\//gis,"").split("\/")
				items.pop()
				
				var objPath:String=items.join("/")
				
				var viewPath:String=Global.workspace.replace(/\\/gis,"/")+"/xml/"+Global.package_view.replace(/\./gis,"/")
					
				var item:Array=viewPath.split("\/")
				item.pop()
				viewPath=item.join("\/")
					
				Global.import_view+="import "+Iv(obj).getClassSpace()+";\n     "
				
				
				}
				
				
			}

			//判断第一个字母是否为数字
			function checkIntOneWord(element:String, index:int, arr:Array):Boolean {

				return ((Number(element.charAt(0)) as Number).toString() != "NaN");
				
			}
			

			if(viewnames.some(checkIntOneWord)){Alert.show("对象名字第一个字母不能为数字！")}

				
			if(viewnames.length!=ArrayControl.defoam(viewnames).length){ Alert.show("对象有重名！")}

		}
		
		function domodel(arr,objs){
		
			//model替换内容========================================
			
			Global.package_model= arr.join(".")+".model"
			
			/*
			for(var  i=0; i<objs.length;i++){
				var obj:ShapeBase=objs[i]
				if(obj.getEvent()!=""){
					
					//Global.var_model+="			private var _"+obj.getName()+";\n"
					//Global.var_model+="			public  function set "+obj.getName()+"(value){ _"+obj.getName()+"=value};\n"
					//Global.var_model+="			public  function get "+obj.getName()+"():*{return "+obj.getName()+"};\n"
					
					Global.function_model+="public function get DefaultModel_"+obj.getEvent()+"():String {\n"
					Global.function_model+="                return getClassName()"+"+\":"+obj.getName()+"\"\n      "
					Global.function_model+="}\n      "
					
				}
			}*/
		
		}
		
		function docommand(arr,objs,scaneName){
		
			arr[1]="commands"
			
			Global.package_command = arr.join(".")+"."+scaneName+"View\n      "
				
			Global.import_commands="import "+Global.package_view+"."+scaneName+"View;"
				
			Global.type_commands=scaneName+"View"
				
			var packageView:String=Global.import_commands
				
			for(var  i=0; i<objs.length;i++){
				
				var obj:ShapeBase=objs[i]
					
				var arr:Array=obj.getEvent().split(".")
					
				if(obj.getEvent()!=""){
					
					//Global.class_commands.push(arr[arr.length-1])
					//优先处理内部事件，e.source.type，上一级接收e.source.source.type
					createFun(arr[arr.length-1])
					
				}
				
			   //if(obj is Iv){BubbleEvent(obj,scaneName)}
				
			}
			
			//生成逻辑处理类	
			
			function createFun(name:String){
				
				//第一个字母大写
				//name=StringControl.onewordUp(name)
				
				var commandSource:String=Global.commandSource
				
				commandSource=commandSource.replace(/<package>/gis,Global.package_command)
				commandSource=commandSource.replace(/<import>/gis,Global.import_commands)
				commandSource=commandSource.replace(/<type>/gis,Global.type_commands)
				
				commandSource=commandSource.replace(/<class>/gis,name)
					
				commandSource=commandSource.replace(/<eventType>/gis,name.split("_")[0])
					
				commandSource=commandSource.replace(/e\.source\.source\.type/gis,"e.source.type")

				var commandPath:String=	Global.workspace.replace(/\\/gis,"/")+"/"+Global.package_command.replace(/\./gis,"/")+"/"+name+".as"
				
				commandPath=commandPath.replace(/\n|\s/gis,"")
				//trace(commandPath,commandSource)	
					
				if(File.desktopDirectory.resolvePath(commandPath).exists==false)FileControl.saveFile(commandPath,commandSource)	
				
			}
		
			
			//递归冒泡事件
		    function BubbleEvent(iv:Iv,scaneName)
			{
				
				var objs:Array=ElementControl.getObjs(ShapeBase,iv)
				
				for(var i=0; i<objs.length;i++){
					
					var obj:ShapeBase=objs[i]
					
					if(obj.getEvent()!=""){
						
						var evts:Array=obj.getEvent().split(".")
							
						var evtName:String=iv.getViewName()+"_"+evts[evts.length-1]
						
						evts.splice(evts.length-1,0,iv.getViewName())

						//Global.class_commands.push(evtName)
						Global.import_commands=packageView+"\n         import "+iv.getClassSpace()	
						createFun(evtName)
							
						var coms:Array=obj.getEventPath(iv.path).split(".")
							
						coms.splice(coms.length-1,0,iv.getViewName())
							
						var str:String=	"AbcEventDispatcher.instance.addEventListener(\""+coms.join(".")+"\","+evtName+");\n         "
						
						if(Global.onEnable_view.indexOf(str)==-1)Global.onEnable_view+=str
							
						str = "AbcEventDispatcher.instance.removeEventListener(\""+coms.join(".")+"\","+evtName+");\n         "
						
						if(Global.offEnable_view.indexOf(str)==-1)Global.offEnable_view+=str
							
						evts.splice(evts.length-2,1,scaneName+"View")
							
						evts.splice(evts.length-1,1,evtName)
							
						str ="function "+evtName+"(e:AbcEvent){\n        AbcEventDispatcher.instance.dispatcher(\""+evts.join(".")+"\",this,e);      }\n\n          "
							
						if(Global.function_view.indexOf(str)==-1)Global.function_view+=str
						
					}
					
					if(obj is Iv){BubbleEvent(obj,scaneName)}
					
				}
			}
				
		}
		
		function docommandControl(arr,objs,scaneName,scene){

			//import ================================================================
			var repSource="public class CommandControl"
			
			/*
			var value="import "+Global.package_view+"."+scaneName+"View;\n"+repSource
				
			var checkStr:String="import "+Global.package_view+"."+scaneName+"View;"
				
			if(Global.commandControlSource.indexOf(checkStr)==-1){
			   Global.commandControlSource=Global.commandControlSource.replace(repSource,value)
			}
			*/

			var paths:Array=Global.package_view.split(".")
			paths[1]="commands"
			paths[paths.length-1]=scaneName+"View"
			
			var value="import "+paths.join(".")+".*;\n"+repSource
			
			var checkStr="import "+paths.join(".")+".*;"
				
			if(Global.commandControlSource.indexOf(checkStr)==-1){
				Global.commandControlSource=Global.commandControlSource.replace(repSource,value)
			}
			
			
			for(var  i=0; i<objs.length;i++){
				
				var obj:ShapeBase=objs[i]
				
				if(obj.getEvent()!=""){
					
					//更新之前删除于此对象相关的所有侦听========================================
					var evts:Array=obj.getEvent().split(".")
					evts.splice(evts.length-1,0,scaneName+"View")
						
					var reg:RegExp=new RegExp("AbcController\\.instance\\.registerCommand\\(\""+evts.join(".")+"\"\)","gis")
					Global.commandControlSource=Global.commandControlSource.replace(reg,"")
					//删除完毕=================================================================

					var evtName:String=obj.getEvent().split(".")[obj.getEvent().split(".").length-1].replace(/Event/gis,"_Event")
						
					repSource="//AbcController.instance.registerCommand()"

					value=repSource+"\n            AbcController.instance.registerCommand(\""+evts.join(".")+"\")"
						
					checkStr="AbcController.instance.registerCommand(\""+evts.join(".")+"\")"
					
					if(Global.commandControlSource.indexOf(checkStr)==-1)Global.commandControlSource=Global.commandControlSource.replace(repSource,value)
							
					repSource="private static var _instance:CommandControl;"
						
					value="private var "+evtName+"_"+scaneName+":"+evts.join(".")+";\n"+repSource
					
					checkStr="private var "+evtName+"_"+scaneName+":"+evts.join(".")+";"
					
					if(Global.commandControlSource.indexOf(checkStr)==-1)Global.commandControlSource=Global.commandControlSource.replace(repSource,value)
						
				}
				
				if(obj is Iv){BubbleEvent(obj,scaneName)}

			}
			
			
			
			
			//递归冒泡事件函数
			function BubbleEvent(iv:Iv,scaneName)
			{
				var objs:Array=ElementControl.getObjs(ShapeBase,iv)
				
				for(var i=0; i<objs.length;i++){
					
					var obj:ShapeBase=objs[i]
					
					if(obj.getEvent()!=""){
						
						//更新之前删除于此对象相关的所有侦听========================================
						var evts:Array=obj.getEvent().split(".")
						evts.splice(evts.length-1,0,scaneName+"View")
						var reg:RegExp=new RegExp("AbcController\\.instance\\.registerCommand\\(\""+evts.join(".")+"\"\)","gis")
						
						Global.commandControlSource=Global.commandControlSource.replace(reg,"")
					
					   //删除完毕=================================================================
						
						var evtName:String=iv.getViewName()+"_"+obj.getEvent().split(".")[obj.getEvent().split(".").length-1].replace(/Event/gis,"_Event")
						
						evts.splice(evts.length-1,1,evtName.replace("_Event","Event"))	
							
							
						repSource="//AbcController.instance.registerCommand()"
						
						value=repSource+"\n            AbcController.instance.registerCommand(\""+evts.join(".")+"\")"
						
						checkStr="AbcController.instance.registerCommand(\""+evts.join(".")+"\")"
						
						if(Global.commandControlSource.indexOf(checkStr)==-1)Global.commandControlSource=Global.commandControlSource.replace(repSource,value)
						
						repSource="private static var _instance:CommandControl;"
						
						value="private var "+evtName+"_"+scaneName+":"+evts.join(".")+";\n"+repSource
						
						checkStr="private var "+evtName+"_"+scaneName+":"+evts.join(".")+";"
						
						if(Global.commandControlSource.indexOf(checkStr)==-1)Global.commandControlSource=Global.commandControlSource.replace(repSource,value)
						
					}
					
					if(obj is Iv){BubbleEvent(obj,scaneName)}
					
				}
			}
		
		}

		function dosave(scaneName){
		
			//替换模板文件=======================================================================
			var viewSource:String=Global.viewSource.replace(/<package>/gis,Global.package_view)
			viewSource=viewSource.replace(/<import>/gis,Global.import_view)
			viewSource=viewSource.replace(/<var>/gis,Global.var_view)
			viewSource=viewSource.replace(/<onEnable>/gis,Global.onEnable_view)
			viewSource=viewSource.replace(/<offEnable>/gis,Global.offEnable_view)
			viewSource=viewSource.replace(/<function>/gis,Global.function_view)
			viewSource=viewSource.replace(/<mouseEvent>/gis,Global.mouseEvent_view)
			viewSource=viewSource.replace(/<events>/gis,Global.events_view)
			viewSource=viewSource.replace(/<init>/gis,Global.init_view)	
				
			
			if(Global.classType_jsfl==AbcType.DOCUMENTCLASSTYPE){
				
				viewSource=viewSource.replace(/public function getInstance\(\):DefaultView \{.*?(?=public function DefaultView\(\))/gis,"")	
				
			}else if(Global.classType_jsfl==AbcType.MOUDLECLASSTYPE){
			
				if(Global.username!=""){
				   viewSource=viewSource.replace("//import","//import\n      import org.control."+Global.username+".CommandControl;\n")
				}else{
				   viewSource=viewSource.replace("//import","//import\n      import org.control.CommandControl;\n")
				}
				
				viewSource=viewSource.replace(/super\.onEnable\(\)/gis,"super.onEnable()\n        CommandControl.instance.initializeController()")
			}
			
			viewSource=viewSource.replace(/Default/gis,scaneName)	

			/*
			var modelSource:String=Global.modelSource.replace(/<package>/gis,Global.package_model)
			modelSource=modelSource.replace(/<var>/gis,Global.var_model)
			modelSource=modelSource.replace(/<function>/gis,Global.function_model)
			modelSource=modelSource.replace(/Default/gis,scaneName)*/
			
			var viewjsflSource:String = Global.viewjsflSource.replace(/<symbolLinkage>/gis,Global.symbolLinkage_jsfl)
			viewjsflSource = viewjsflSource.replace(/<items>/gis,Global.items_jsfl)
			viewjsflSource = viewjsflSource.replace(/<classType>/gis,Global.classType_jsfl)
			viewjsflSource = viewjsflSource.replace(/<as3PackagePath>/gis,Global.as3PackagePath_jsfl)	
			

				
			//生成文件
			var viewpath:String=Global.workspace.replace(/\\/gis,"/")+"/"+Global.package_view.replace(/\./gis,"/")+"/"+scaneName+"View.as"
			
			var modelpath:String=Global.workspace.replace(/\\/gis,"/")+"/"+Global.package_model.replace(/\./gis,"/")+"/"+scaneName+"Model.as"
			
				
			switch(Global.classType_jsfl){
			
			
			     case AbcType.DOCUMENTCLASSTYPE:
					 
					 //var viewjsflpath:String=Global.workspace.replace(/\\/gis,"/")+"/jsfl/module/"+Global.package_view.replace(/\./gis,"/")+"/"+scaneName+"View.jsfl"
					 
					 break
				
				 case AbcType.CLASSTYPE:
					 
				 case AbcType.MOUDLECLASSTYPE:
			
					 var arr:Array=Global.package_view.split(".")
					 arr.pop()
					 var viewjsflpath:String=Global.workspace.replace(/\\/gis,"/")+"/jsfl/"+arr.join("/")+"/"+scaneName+"View.jsfl"
					 
					 break
			
			}	
				
			//生成逻辑处理类	
			/*
			for(var i=0;i<Global.class_commands.length;i++){
				
				var commandSource:String=Global.commandSource
					
				commandSource=commandSource.replace(/<package>/gis,Global.package_command)
					
				commandSource=commandSource.replace(/<import>/gis,Global.import_commands)
					
				commandSource=commandSource.replace(/<type>/gis,Global.type_commands)
					
				commandSource=commandSource.replace(/<class>/gis,Global.class_commands[i])
					
				commandSource=commandSource.replace(/<eventType>/gis,Global.class_commands[i].split("_")[0])
				
					
				var commandPath:String=	Global.workspace.replace(/\\/gis,"/")+"/"+Global.package_command.replace(/\./gis,"/")+"/"+Global.class_commands[i]+".as"
				
				//trace(Global.workspace.replace(/\\/gis,"/"))
				//trace(Global.package_command.replace(/\./gis,"/"))
				//trace(commandPath,commandSource)
					
				commandPath=commandPath.replace(/\n|\s/gis,"")
				
				if(File.desktopDirectory.resolvePath(commandPath).exists==false)FileControl.saveFile(commandPath,commandSource)	
					
			}*/
			
			//修改CommandControl.as
			var commandControlPath:String =	Global.workspace.replace(/\\/gis,"/")+"/org/control/"+Global.username+"/CommandControl.as"
				

			//修改modelProxy.as
			/*var modelProxySource:String=Global.modelProxySource.replace("<package>",Global.package_modelProxy)
			modelProxySource=modelProxySource.replace("<import>",Global.import_modelProxy)
			modelProxySource=modelProxySource.replace("<model>",Global.model_modelProxy)
			modelProxySource=modelProxySource.replace("<view>",Global.view_modelProxy)
			modelProxySource=modelProxySource.replace(/Default/gis,scaneName)
			var modelProxypath:String=Global.workspace.replace(/\\/gis,"/")+"/"+Global.package_modelProxy.replace(/\./gis,"/")+"/"+scaneName+"ModelProxy.as"
            */
				
			//修改viewProxy.as
			var viewProxySource:String=Global.viewProxySource.replace("<package>",Global.package_viewProxy)
			viewProxySource=viewProxySource.replace("<import>",Global.import_viewProxy)
			viewProxySource=viewProxySource.replace("<model>",Global.model_viewProxy)
			viewProxySource=viewProxySource.replace("<view>",Global.view_viewProxy)
			viewProxySource=viewProxySource.replace(/Default/gis,scaneName)		
				
				
			var viewProxypath:String=Global.workspace.replace(/\\/gis,"/")+"/"+Global.package_viewProxy.replace(/\./gis,"/")+"/"+scaneName+"ViewProxy.as"
				
            try{
			
			//if(File.desktopDirectory.resolvePath(modelProxypath).exists==false)FileControl.saveFile(modelProxypath,modelProxySource)	
				
			if(File.desktopDirectory.resolvePath(viewProxypath).exists==false)FileControl.saveFile(viewProxypath,viewProxySource)
				
			FileControl.saveFile(commandControlPath,Global.commandControlSource)	
			FileControl.saveFile(viewpath,viewSource)
			//if(File.desktopDirectory.resolvePath(modelpath).exists==false)FileControl.saveFile(modelpath,modelSource)
			FileControl.saveFile(viewjsflpath,viewjsflSource)
				
			}catch(e:Error){
				
			//trace(commandControlPath,viewpath,modelpath,viewjsflpath,modelProxypath,viewProxypath)
			
			}
		
		}

	}
}